#ifndef __dns_h__ 
#define __dns_h__ 1


#include "sys.h"
#include "net.h"

typedef struct {
    uint16_t id;
    uint16_t flags;
    uint16_t questions;
    uint16_t answer_RRs, authority_RRs, addtional_RRs;
    char data[0];
}dns_t;

enum{
    DNS_SUCCESS = 0,
    DNS_ERR_GETADDR = -1,
    DNS_ERR_CONNECT = -2,
    DNS_ERR_WRITE = -3,
    DNS_ERR_READ = -4,
};

typedef struct{
    char dns_svr[32];
    uint16_t port;
    char domain[1024];
    int timeout;
}dns_arg_t;

typedef struct{
    float latency;
    uint32_t ipaddr[4];
    int rcode;
}dns_result_t;

extern void* do_dns(void *arg);
extern dns_t *dns_packet(char *domain, int *len);
extern void dns_packet_free(dns_t *dp);
void dns_result_print(dns_result_t* result);
#endif